import bpy


def topbar(self: bpy.types.Panel, context):
    from ..ops.queue import SwitchQueueUI
    layout = self.layout
    region = context.region
    name = self.__class__.__name__

    def ops(lay):
        lay.operator(SwitchQueueUI.bl_idname,
                     icon='RESTRICT_RENDER_OFF',
                     text='',
                     emboss=False,
                     ).popup_window = True

    if name == 'USERPREF_MT_editor_menus':
        layout.separator_spacer()
        layout.separator_spacer()
        layout.separator_spacer()
        layout.separator_spacer()
        layout.separator_spacer()
        ops(layout)
    elif name == 'USERPREF_PT_save_preferences':
        ops(layout.row())
    elif name == 'TOPBAR_MT_editor_menus':
        if region.alignment == 'RIGHT':
            ...
        else:
            ops(layout)


class_tuple = (
)
reg_class, un_reg_class = bpy.utils.register_classes_factory(class_tuple)


def register():
    reg_class()
    if bpy.types.TOPBAR_MT_editor_menus:
        bpy.types.TOPBAR_MT_editor_menus.append(topbar)
    bpy.types.USERPREF_MT_editor_menus.append(topbar)
    bpy.types.USERPREF_PT_save_preferences.append(topbar)


def unregister():
    un_reg_class()
    
    if bpy.types.TOPBAR_MT_editor_menus:
        bpy.types.TOPBAR_MT_editor_menus.remove(topbar)

    bpy.types.USERPREF_MT_editor_menus.remove(topbar)
    bpy.types.USERPREF_PT_save_preferences.remove(topbar)
